// 用 a 标签下载 url 的文件
export function downloadByATagWithUrl({ url, fileName }) {
  const a = document.createElement('a')
  a.style.display = 'none'
  a.href = url
  a.target = '_blank'
  a.download = fileName
  document.body.appendChild(a)
  a.click()
  document.body.removeChild(a)
}

// 下载 txt 文件
export const saveTxtFile = function({ data, fileName }) {
  downloadByATagWithUrl({
    url: 'data:text/plain;charset=utf-8,' + encodeURIComponent(data),
    fileName
  })
}
